package com.rj.bd.userinto.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rj.bd.userinto.entity.Userinto;
import com.rj.bd.userinto.service.IUserintoService;

@ResponseBody
@Controller
@RequestMapping("/userinto")
public class UserintoController {
	@Autowired
	public IUserintoService  userintoService;
	
	@RequestMapping("/login")
	@CrossOrigin
	public Map<String,Object> login(HttpServletRequest request){
		 String uuname = request.getParameter("uuname");
		 String uupassword = request.getParameter("uupassword");
	     Map<String, Object> json=new HashMap<String, Object>();
	     if (uuname==null||uuname.equals("")) {
				json.put("login", "0");
			
				return json;
			}
	     if (uupassword==null||uupassword.equals("")) {
				json.put("login", "0");
				
				return json;
	     }
	     Userinto userinto = userintoService.login(uuname,uupassword);
	     if (userinto==null) {
	 		json.put("login","0");
	 		return json;
	 	}
	     
		String uutoken=uuname+uupassword+request.getSession().getId();
		userintoService.update(uutoken,userinto.getUuid());
		json.put("login","1");
		json.put("code","200");
		json.put("uutoken", uutoken);
		System.out.println("uuname:"+uuname);
		System.out.println("uupassword:"+uupassword);
		
		return json;
		
	
	}
	
	
	

	
}
